﻿using System;
using System.Windows.Forms;
using MPMovieCatalog.Util;

namespace MPMovieCatalog.Configuration.Sections
{
    public partial class ConnectionSectionForm : ConfigurationFormSection
    {

        private ConnectionSection m_connectionSection;

        public ConnectionSectionForm(ConnectionSection connectionSection)
            : this(ResourceUtils.GetString("options", 3))
        {
            m_connectionSection = connectionSection;
        }

        public ConnectionSectionForm(string text)
            : base(text)
        {
            InitializeComponent();
            UpdateUI();
            this.Load += new EventHandler(ConnectionSectionForm_Load);
        }

        private void ConnectionSectionForm_Load(object sender, EventArgs e)
        {
            Binding bindingHost = new Binding("Text", m_connectionSection,
                        "Host", true, DataSourceUpdateMode.OnPropertyChanged);
            hostTextBox.DataBindings.Add(bindingHost);

            Binding bindingPort = new Binding("Value", m_connectionSection,
                        "Port", true, DataSourceUpdateMode.OnPropertyChanged);
            portUpDown.DataBindings.Add(bindingPort);
        }

        private void UpdateUI()
        {
            hostLabel.Text = ResourceUtils.GetString("options", 4);
            portLabel.Text = ResourceUtils.GetString("options", 5);
        }

    }
}
